package com.service;

import javax.xml.ws.Endpoint;

import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;

import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class MargoWebServiceConfig {
	
	@Autowired
    private Service serviceDelegate;
	
 
    /**
     * 		不注册则 http://localhost:8080/services/fxbservice?wsdl
     * 	注入servlet  bean name不能dispatcherServlet 否则会覆盖dispatcherServlet
     * @return
     */
    @Bean(name = "cxfServlet")
    public ServletRegistrationBean<CXFServlet> cxfServlet() {
        return new ServletRegistrationBean<CXFServlet>(new CXFServlet(),"/vss/2.0/workflow/*");
    }
 
 
    @Bean(name = Bus.DEFAULT_BUS_ID)
    public SpringBus springBus() {
        return new SpringBus();
    }
 
    /**
     * 	注册WebServiceDemoService接口到webservice服务
     * @return
     */
    @Bean(name = "MargoWebServiceEndpoint")
    public Endpoint margoPayEndpoint() {
        EndpointImpl endpoint = new EndpointImpl(springBus(), serviceDelegate);
        endpoint.publish("/CSGServiceServiceSync");
        return endpoint;
    }
}
